package com.coco.controller;

import com.coco.model.NaviInfo;
import com.coco.model.NaviInfoCondition;
import com.coco.service.NaviService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author GHOSTLaycoo
 * @date 2020/4/7 0007 - 上午 9:19
 */
@RestController
@RequestMapping("/navi")
@Slf4j
public class NaviController {
    @Autowired
    private NaviService naviService;

    @ApiOperation(value = "保存导航栏信息")
    @PostMapping("/save")
    public ResponseEntity<Integer> save(@RequestBody NaviInfo naviInfo){
        int result =  naviService.save(naviInfo);
        return ResponseEntity.status(HttpStatus.CREATED).body(result);
    }

    @ApiOperation(value = "删除导航栏信息")
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Integer> delete(@PathVariable("id") String id){
        int result =  naviService.delete(id);
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value = "修改导航栏信息")
    @PostMapping("/update")
    public ResponseEntity<Integer> update(@RequestBody NaviInfo naviInfo){
        int result =  naviService.update(naviInfo);
        return ResponseEntity.status(HttpStatus.CREATED).body(result);
    }

    @ApiOperation(value = "查询导航栏信息")
    @PostMapping("/getNaviByCondition")
    public ResponseEntity<List<NaviInfo>> getNaviByCondition(@RequestBody NaviInfoCondition naviInfoCondition){
        List<NaviInfo> result =  naviService.getNaviByCondition(naviInfoCondition);
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value = "获取类型数据")
    @GetMapping("/getNavis")
    public ResponseEntity<List<NaviInfo>> getNavis(){
        List<NaviInfo> result =  naviService.getNavis();
        return ResponseEntity.ok(result);
    }
}
